package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties("handler") //handler属性不转换成JSON
//游记对象
public class Travel extends BaseDomain {
    public static final Integer STATE_REFUSE = -1; //拒绝
    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_WAIT = 1; //待审核
    public static final Integer STATE_RELEASE = 2; //审核通过

    private String title; //标题

    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
    private Date travelTime; //旅游时间

    private String perExpends; //人均消费

    private Integer days; //游玩天数

    private Integer person; //跟xx游玩

    @JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
    private Date createTime; //创建时间

    @JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
    private Date releaseTime; //发布时间

    private Boolean isPublic = false; //是否公开,默认不公开

    private String coverUrl; //封面

    @JsonFormat(pattern="yyyy-MM-dd HH:mm", timezone="GMT+8")
    private Date lastUpdateTime; //最后更新时间

    private Integer state = STATE_TEMP; //状态

    private Region place; //旅游区域

    private User author; //作者

    private TravelContent travelContent; //游记内容

    private Integer enshrineNumber; //被收藏数量

    public String getStateName() {
        String msg = "草稿";
        if (state == STATE_REFUSE) {
            msg = "拒绝";
        } else if (state == STATE_WAIT) {
            msg = "待审核";
        } else if (state == STATE_RELEASE) {
            msg = "审核通过";
        }
        return msg;
    }

    public String getPersonName() {

        String msg = "一个人的旅行";
        if(person!=null) {
            if (person == 2) {
                msg = "和父母";
            } else if (person == 3) {
                msg = "和朋友";
            } else if (person == 4) {
                msg = "和同事";
            } else if (person == 5) {
                msg = "和爱人";
            } else if (person == 6) {
                msg = "和驴友";
            }
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        return JSONUtil.toJSONString(map);
    }
}